﻿using Autofac;
using Common.Utils;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System.Reflection;

namespace TakeawayWebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ToolsController : ControllerBase
    {
        private readonly ISqlSugarClient _db;
        public ToolsController(ISqlSugarClient db)
        {
            _db = db;
        }

        [HttpGet]
        public bool InitDataBase()
        {
            //初始化数据库:如果不存在则创建数据库
            _db.DbMaintenance.CreateDatabase();
            //创建表
            string nspace = "Model.Entitys";
            Type[] ass = Assembly.LoadFrom("bin/Debug/net6.0/Model.dll").GetTypes().Where(p => p.Namespace == nspace).ToArray();
             _db.CodeFirst.SetStringDefaultLength(255).InitTables(ass);
            return true;
        }
        [HttpGet]
        public bool InitEntitys()
        {
           _db.DbFirst.IsCreateAttribute()
                .CreateClassFile("D:\\reggie\\Takeaway\\Model\\Entitys", "Model.Entitys");
            return true;
        }
        //[HttpGet]
        //public void SmsTest()
        //{
        //    AliyunSmsApi.SendSms("17666182489", "123456");
        //}
    }
}
